package top.v5it.japi.ddd.core.repository;

import org.apache.ibatis.cursor.Cursor;
import top.v5it.japi.ddd.core.dao.BasicDao;
import top.v5it.japi.ddd.core.dao.impl.Wrapper;
import top.v5it.japi.ddd.core.entity.Entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * @author fangang
 */
public abstract class DecoratorDao implements BasicDao {

    protected BasicDao dao;

    /**
     * @return the dao
     */
    public BasicDao getDao() {
        return dao;
    }

    /**
     * @param dao the dao to set
     */
    public void setDao(BasicDao dao) {
        this.dao = dao;
    }


    @Override
    public <T> void insert(T entity) {
        getDao().insert(entity);
    }

    @Override
    public <T> void update(T entity) {
        getDao().update(entity);
    }

    @Override
    public <T> void insertOrUpdate(T entity) {
        getDao().insertOrUpdate(entity);
    }

    @Override
    public <T, S extends Collection<T>> void insertOrUpdateForList(S list) {
        getDao().insertOrUpdateForList(list);
    }

    @Override
    public <T> void delete(T entity) {
        getDao().delete(entity);
    }

    @Override
    public <T, S extends Collection<T>> void deleteForList(S list) {
        getDao().deleteForList(list);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> void deleteForList(Collection<S> ids, T template) {
        getDao().deleteForList(ids, template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> T load(S id, T template) {
        return getDao().load(id, template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> List<T> loadForList(Collection<S> ids, T template) {
        return getDao().loadForList(ids, template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> List<T> loadAll(T template) {
        return getDao().loadAll(template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> void delete(S id, T template) {
        getDao().delete(id, template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> List<T> cursorAll(T template, Predicate<T> test) {
        return getDao().cursorAll(template, test);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> Cursor<Map<String, Object>> cursorAll(T template) {
        return getDao().cursorAll(template);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> List<T> loadAllByCondition(Wrapper<T> wrapper) {
        return getDao().loadAllByCondition(wrapper);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> List<Map<String, Object>> loadAllByCombination(Wrapper<T> wrapper) {
        return getDao().loadAllByCombination(wrapper);
    }

    @Override
    public <T> List<T> execute(Wrapper<T> wrapper) {
        return getDao().execute(wrapper);
    }

    @Override
    public <T> Optional<T> one(Wrapper<T> wrapper) {
        return getDao().one(wrapper);
    }

    @Override
    public <S extends Serializable, T extends Entity<S>> Cursor<Map<String, Object>> cursorAll(Wrapper<T> wrapper) {
        return getDao().cursorAll(wrapper);
    }

    @Override
    public <T, S extends Collection<T>> void jdbcInsertForList(S list) {
        getDao().jdbcInsertForList(list);
    }
}